package com.example.spring.controller;


import com.example.spring.entity.Warehouse;
import com.example.spring.mapper.WarehouseMapper;
import com.example.spring.service.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/warehouse")
public class WarehouseController {

    @Autowired
    private WarehouseMapper warehouseMapper;

    @Autowired
    private WarehouseService warehouseService;

    //新增或修改
    @PostMapping()
    public Integer save(@RequestBody Warehouse warehouse) {
        //新增或者更新
        return warehouseService.save(warehouse);
    }
    //查询所有数据
    @GetMapping()
    public List<Warehouse> findAll() {
        List<Warehouse> all =  warehouseMapper.findAll();
        return all;
    }
    //删除
    @DeleteMapping("/{whid}")
    public Integer delete(@PathVariable Integer whid)
    {
        return warehouseMapper.deleteById(whid);
    }

}
